<?php
class ControllerReportCustomerOrder extends AdminController {
	public function index() {

		$this->document->setTitle($this->_['heading_title']);

		M('report/customer');

		$this->data['customers'] = array();

		$qf = new Query_filter();
		$customer_total = $this->model_report_customer->getTotalOrders($qf);
		$results = $this->model_report_customer->getOrders($qf);

		foreach ($results as $result) {
			$action = array();

			$action[] = array(
				'text' => $this->_['text_edit'],
				'href' => UA('sale/customer/update', 'customer_id=' . $result['customer_id'])
			);

			$this->data['customers'][] = array(
				'customer'       => $result['customer'],
				'email'          => $result['email'],
				'customer_group' => $result['customer_group'],
				'status'         => ($result['status'] ? $this->_['text_enabled'] : $this->_['text_disabled']),
				'orders'         => $result['orders'],
				'products'       => $result['products'],
				'total'          => $this->currency->format($result['total'], C('config_currency')),
				'action'         => $action
			);
		}

		$this->data['order_statuses'] = C('cache_order_status');

		$this->data['pagination'] = $this->pagination($customer_total)->render();
		
		$this->data['filter_date_start'] = $qf->get('filter_date_start', '');
		$this->data['filter_date_end'] = $qf->get('filter_date_end', '');
		$this->data['filter_order_status_id'] = $qf->get('filter_order_status_id', 0);

		$this->display('report/customer_order.tpl');
	}
}
?>